home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / dosbasic.zip / ASM.ZIP / CHIPID.ASM < prev    next >
Assembly Source File  |  1990-12-19  |  7KB  |  204 lines

  1. ;«RM82»«TS8,16,24,32,40,48»
  2. ;Updated 12/14/90
  3.  
  4. DOSSEG
  5. .MODEL MEDIUM
  6.  
  7.      PUBLIC GETCPU
  8.  
  9. .code
  10. ;==============================================================================
  11. ;PreFetchQueue
  12. ;       On exit:
  13. ;
  14. ;               DX      = length of prefetch instruction queue
  15. ;
  16. ;       This subroutine uses self-modifying code, but can
  17. ;       nevertheless be run repeatedly in the course of the calling
  18. ;       program, since only executed in real mode by pre 286 chips
  19. ;
  20. ;  This routine came from the public domain program InfoPlus Ver 1.35
  21. ;  by Andrew Rossman 10/7/90
  22. ;
  23. ;  I believe that the logic came from earlier efforts:
  24. ;Copyright free.
  25. ;  Bob Smith            May 1985.
  26. ;  Qualitas, Inc.
  27. ;  8314 Thoreau Dr.
  28. ;  Bethesda, MD  20817
  29. ;  301-469-8848
  30. ;
  31. ;  Bob Smith credited Arthur Zachai with suggesting the technique to dis-
  32. ;  tinguish  between  the 808x and 8018x families by exploiting the 
  33. ;  difference in the length of their pre-fetch instruction queues.
  34. ;==============================================================================
  35. count   =       7
  36. opincDX equ     42H                     ; inc DX opcode
  37. opnop   equ     90H                     ; nop opcode
  38.  
  39. ; Please do not remove
  40. Copyright       DB    13,10,'Copyright Copr. (C) 1990 Sidney J. Kelly',13,10
  41. Copyright1      DB    'All Rights Reserved',13,10,26
  42.  
  43. EVEN
  44. PreFetchQueue     proc    near
  45.     Mov     AL,opincDX
  46.     Mov     CX,count
  47.     Push    CX
  48.     Push    CS
  49.     Pop     ES
  50.     Mov     DI,offset PreFetchQueue_01 - 1
  51.     Push    DI
  52.     STD
  53.     Rep stosb
  54.     Mov     AL,opnop
  55.     Pop     DI
  56.     Pop     CX
  57.     Xor     DX,DX
  58.     CLI
  59.     rep stosb
  60.     rept    count
  61.     inc     DX
  62.     endm
  63. PreFetchQueue_01:
  64.     STI
  65.     cld
  66.     Ret
  67. PreFetchQueue     endp
  68.  
  69. ;==============================================================================
  70. ; DECLARE FUNCTION GETCPU% ()
  71. ; Checks for CPU type
  72. ; Returns:
  73. ;    88 for 8088
  74. ;    86 for 8086
  75. ;    20 for NEC V20
  76. ;    30 for NEC V30
  77. ;    186 for 80186 or 80188 (I have never seen an 80188 so no special test)
  78. ;    286 for 80286
  79. ;    386 for 80386
  80. ;    386 for 80486.  I offer no special test for 80486 because the only 
  81. ;            published code I found in PC Magazine wrecks Windows
  82. ;            I can't offer other code because I don't have     MS MASM
  83. ;            or Borland TASM so as to compile protected mode
  84. ;            software.  The Code that crashes Windows is shown below
  85. ;
  86. ;       Based on uncopyrighted, published logic by
  87. ;         Clif (that's the way he spells it) Purkiser of Intel -
  88. ;         Santa Clara.  Now set forth in the MS's published HIMEM.SYS as the
  89. ;      "oficial Intel Method."
  90. ;
  91. ;         Some ideas by Pat Shea from his 
  92. ;         Pat Shea' Copr. 1987 routine  "(that Copr. is on there cuz my
  93. ;                                        lawyer sez I should, but feel
  94. ;                                        free to hack away!!!    pats.)"
  95. ;      As improved by DON HIGGINS (COMPUSERVE 73047,1113) (MASM code)
  96. ;      Fixed 05/25/88 73710,3667 TRT
  97. ;
  98. ;         Most of this routine came from the public domain program InfoPlus
  99. ;      Ver 1.35 by Andrew Rossman 10/7/90.  I reordered it to preserve
  100. ;      the necessary registers for QBASIC and eliminate the unknown chip
  101. ;      value.
  102. ;==============================================================================
  103.  
  104. EVEN
  105. GETCPU     PROC     FAR
  106.     Push    SI              ; because we will change it
  107.     Push    DI
  108.     Pushf            ; prepare to manipulate flag register
  109.     Xor    AX,AX        ; must do it through pushs and pops
  110.     Push    AX        ; because no direct method to manipulate
  111.     Popf            ; put a 0 in the flags
  112.     Pushf
  113.     Pop    AX        ; get value back from flags
  114.     And    AX,8000h    ; chips less than 286 wont clear high bits of
  115.     Cmp    AX,8000h    ; flags.  All bits set on 808x, NEC, 8018x?
  116.     JE    Test_Real    ; yep, so check for NEC, 808x, 8018x chips
  117.     Mov    AX,7000h    ; else see if set other flag bits
  118.     Push    AX        ; to distinguish 286 from 386/486 chip
  119.     Popf
  120.     Pushf
  121.     Pop    AX
  122.     And    AX,7000h    ; bits 12 -14 can't be set in real mode on 286
  123.                 ; the NT & IOPL bits
  124.     Jz    Found_286    ; if can't set, then have a 286
  125.  
  126. Found_386:
  127.     Mov    AX,386        ; else report have a 386 or 486
  128.     Jmp    short Finis
  129.  
  130. Found_286:
  131.     Mov    AX,286        ; report have a 286
  132.     Jmp    short Finis
  133.  
  134. Test_Real:
  135.     Mov    AX,0ffffh    ; see if can shift left more than 32 times
  136.     Mov    CL,21h        ; 8018x chips (286/386/486 too) wont allow this
  137.     Shl    AX,CL        ; but 808x chips will shift AX to 0
  138.     Jnz    Found_186
  139.  
  140. Test_86:
  141.     Call    PreFetchQueue   ; find length of PIQ
  142.                 ; result returned in DX
  143.     STI            ; interrupts must be allowed
  144.     Xor    SI,SI        ; clear offset address
  145.     Mov     CX,-1        ; load 64k in CX for size of loop
  146.     Rep     Lods Byte Ptr ES:[SI]    ; only  NEC can rep w/ segment override
  147.     JCXZ    short Test_NEC    ; if CX got to 0 then we have a NEC
  148.  
  149.     Mov    BX,86        ; assume an 8086
  150.     Cmp     DX,4        ; was PIQ = 4, then have an 8088
  151.     Ja    @f        ; if more than 4 have 8086
  152.     Mov    BX,88        ; else report 8088
  153. @@:
  154.     Mov    AX,BX        ; get value back from BX
  155.     Jmp    short Finis
  156.  
  157. Test_NEC:
  158.     Mov    BX,30        ; assume a V30
  159.     Cmp    DX,4        ; if PIQ = 4, then have a V20
  160.     Ja    @f        ; if more than 4, then have a V30
  161.     Mov    BX,20        ; else report a V20
  162. @@:
  163.     Mov    AX,BX        ; get value back from BX
  164.     Jmp    Short Finis
  165.  
  166. Found_186:
  167.     Mov    AX,186        ; report have an 80186 (Tandy 2000)
  168.                 ; I have never seen an 80188 so that is not
  169.                 ; tested for.  If you want to test use prefetch 
  170.                 ; instruction que test.
  171. Finis:
  172.     Popf
  173.     Pop    DI
  174.     Pop    SI        ; because we changed it
  175.     Ret
  176. GETCPU     ENDP
  177.  
  178. Comment        |
  179. check_for_80386:
  180.  
  181. ;=====================================================================;
  182. ;   Cpu type is an 80386 Or 80486       PCMAG, July 1990, page 426
  183. ;  Unfortunately, use of this CODE will cause WINDOWS 3.0 to request that
  184. ;  the user reboot (a violation of protected mode security)
  185. ;  So .code is commented out.  I suspect in protected mode that there
  186. ;  is no way to determine the difference between a 386 or 486 because
  187. ;  any test will cause a violation of some protected mode feature.
  188. ;=====================================================================;
  189.     DB                 0Fh,20h,0C0h             ;Mov EAX,CR0
  190.     DB                 66h,8Bh,0D8h             ;Mov EBX,EAX
  191.     DB                 66h,35h,00,00,00,20h     ;Xor EAX,20000000h
  192.     DB                 0Fh,22h,0C0h             ;Mov CR0,EAX
  193.     DB                 0Fh,20h,0C0h             ;Mov EAX,CR0
  194.     DB                 66h,3Bh,0C3h             ;Cmp EAX,EBX
  195.     JE                 is_386
  196.     DB                 0Fh,22h,0C3h             ;Mov CR0,EBX
  197.     Mov                AX,486
  198.     Jmp                Short Finis
  199. is_386:
  200.  
  201.     Mov                AX, 386
  202.     |
  203. END
  204.